package com.dianning.web.action.user;

import java.util.Date;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.*;
import org.apache.struts2.interceptor.SessionAware;

import com.dianning.bean.Company;
import com.dianning.bean.Message;
import com.dianning.bean.Orders;
import com.dianning.bean.Resume;
import com.dianning.bean.UserDetail;
import com.dianning.bean.UserInfo;
import com.dianning.bean.Visitor;
import com.dianning.comm.Constant;
import com.dianning.comm.OrderObj;
import com.dianning.comm.Util;
import com.dianning.service.InfoService;
import com.dianning.service.MessageService;
import com.dianning.service.OrdersService;
import com.dianning.service.UserInfoService;
import com.dianning.service.VisitorService;
import com.dianning.service.web.PageList;
import com.dianning.service.web.Pages;
import com.dianning.web.action.BaseAction;
import com.dianning.web.interceptor.UserSessionAware;
import com.dianning.web.servlet.UserSession;

public class OrdersAction extends BaseAction implements SessionAware, UserSessionAware{

	private static final Log logger = LogFactory.getLog(OrdersAction.class);

	private UserInfoService userInfoService;
	private OrdersService ordersService;


	public UserInfoService getUserInfoService() {
		return userInfoService;
	}

	public void setUserInfoService(UserInfoService userInfoService) {
		this.userInfoService = userInfoService;
	}

	public OrdersService getOrdersService() {
		return ordersService;
	}

	public void setOrdersService(OrdersService ordersService) {
		this.ordersService = ordersService;
	}

	private UserSession userSession;
	private Map session;
	
	public UserSession getUserSession() {
		return userSession;
	}

	public void setUserSession(UserSession userSession) {
		this.userSession = userSession;
	}
	
	public Map getSession() {
		return session;
	}
	
	public void setSession(Map session) {
		this.session = session;
	}
	
	private long id;
	private String username;
	private String message;
	private String verifycode;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getVerifycode() {
		return verifycode;
	}

	public void setVerifycode(String verifycode) {
		this.verifycode = verifycode;
	}
	
	private PageList pageList;

	public PageList getPageList() {
		return pageList;
	}

	public void setPageList(PageList pageList) {
		this.pageList = pageList;
	}	

	
	
	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return ERROR;
		}
	}
	
	public String index(){
		Pages pages = new Pages();
		pages.setPage(this.getPage());
		pages.setPerPageNum(Constant.USER_PAGE_NUM);
		if (this.getTotal() > 0) {
			pages.setTotalNum(this.getTotal());
		}
		pages.setFileName("/user/orders.action");
		this.setPageList(this.getOrdersService().findOrders(userSession.getUid(), -1, 0, "addTime", 1, pages));
		this.getOrdersService().updateOrdersIsnew(userSession.getUid(), 0);
		return "index";
	}
	
	public String del(){
		Orders o = this.getOrdersService().findOrdersById(this.id);
		if(o.getUid() == userSession.getUid()){
			o.setDelstatus(1);
			this.getOrdersService().updateOrders(o);
		}
		this.message = "{success:'true'}";
		return "message";
	}

}
